<!DOCTYPE html>
<html>
<head>
<include file="Include:meta" />
<title>PBC指标-目的地运营集团数据管理平台</title>
<include file="Include:style" />
<style>
	.folder span{ display: inline-block; margin: 0 40px 0 1px; }
	.w50{ width: 50px; text-align: center; }
</style>
</head>
<body>
<include file="Include:header" />
<include file="Include:left" />
<div id="main">
	<div class="crumbs">
		<div class="crumbs-text">PBC管理 > 人员PBC</div>
		<if condition="$u_id neq -10 && $status eq -1">
		<if condition="is_permission('PB',NULL,1)">
		<div class="right">
			<a href="javascript:;" class="btn btn-add">添加人员PBC</a>
		</div>
		</if>
		</if>
	</div>
	<div id="content">
		<div class="classify">
			<ul>
				<li><a href="__APP__/Hr/jixiao_pbc">指标库</a></li>
				<li><a href="__APP__/Hr/jixiao_pbc_position">职位PBC</a></li>
				<li><a href="javascript:;" class="current">人员PBC</a></li>
				<li><a href="__APP__/Hr/jixiao_pbc_view">PBC总览</a></li>
			</ul>
		</div>
		<form class="number_validate" action="#" method="post" enctype="multipart/form-data">
		<div class="filter">
			<div class="filter-item">
				<div class="filter-title">请选择人员：
					<select name="u_id" class="form-control" style="width:85px;">
						<option value="-10"<if condition="$u_id eq -10"> selected</if>>姓名</option>
						<foreach name="result1" item="vo">
						<option value="{$vo['id']}"<if condition="$u_id eq $vo['id']"> selected</if>>{$vo['username']}</option>
						</foreach>
					</select>
					<if condition="is_permission('PB',NULL,1)">
					<if condition="$u_id neq -10"><a href="javascript:;" class="btn ml20 synchro" action="sync" u_id="{$u_id}">同步到指标库</a></if>
					</if>
					<if condition="$u_id neq -10">
						<if condition="is_permission('PB',NULL,1)">
							<if condition="$status eq -1">
							<div class="right">
								<p>签署日期：<input type="text" name="qy_date" value="{$qy_date}" class="form-control Wdate ml5 w100" onclick="WdatePicker()" readonly autocomplete="off"></p>
							</div>
							<div class="right mr20">
								<p>合同期限：由<input type="text" name="ht_sdate" value="{$ht_sdate}" class="form-control Wdate ml10 mr10 w100" id="d34" <literal>onclick="WdatePicker({maxDate:'#F{$dp.$D(\'d12\')}'})"</literal> readonly autocomplete="off">至<input type="text" name="ht_edate" value="{$ht_edate}" class="form-control Wdate ml10 w100" id="d12" <literal>onclick="WdatePicker({minDate:'#F{$dp.$D(\'d34\')}'})" readonly autocomplete="off"></literal></p>
							</div>
							<div class="right mr10">
								<span class="ml10">发约人：</span>
								<select name="out_uid" class="form-control w100" autocomplete="off">
									<option value="-10"<if condition="$out_uid eq -10"> selected</if>>姓名</option>
									<foreach name="result1" item="vo">
									<option value="{$vo['id']}"<if condition="$out_uid eq $vo['id']"> selected</if>>{$vo['username']}</option>
									</foreach>
								</select>
							</div>
							<else />
							
							<div class="right mt10">
								<p>签署日期：{$qy_date}</p>
							</div>
							<div class="right mt10 mr20">
								<p>合同期限：由{$ht_sdate}至{$ht_edate}</p>
							</div>
							<div class="right mt10 mr10">
								<span class="ml10">发约人：{$out_name['username']}</span>
							</div>
							</if>
						<elseif condition="$qy_date neq NULL" />
							<div class="right mt10">
								<p>签署日期：{$qy_date}</p>
							</div>
							<div class="right mt10 mr20">
								<p>合同期限：由{$ht_sdate}至{$ht_edate}</p>
							</div>
							<div class="right mt10 mr10">
								<span class="ml10">发约人：{$out_name['username']}</span>
							</div>
						</if>
					</if>
				</div>
			</div>
		</div>
		<if condition="$u_id neq -10">
		<div class="">
			<table class="table table-bordered">
				<tr class="table-header fixed-table-header">
					<td rowspan="2" style="text-align:center;vertical-align:middle;">指标类型</td>
					<td rowspan="2" style="text-align:center;vertical-align:middle;">关键绩效指标（KPI）</td>
					<td rowspan="2" style="text-align:center;vertical-align:middle;">单位</td>
					<td rowspan="2" style="text-align:center;vertical-align:middle;">权重</td>
					<td rowspan="2" style="text-align:center;vertical-align:middle;">考核周期</td>
					<td rowspan="2" style="text-align:center;vertical-align:middle;">管理</td>
					<td colspan="3" style="text-align:center;vertical-align:middle;">目标等级</td>
					<td rowspan="2" style="text-align:center;vertical-align:middle;">实际完成值</td>
					<td rowspan="2" style="text-align:center;vertical-align:middle;">考核得分</td>
				</tr>
				<tr class="table-header fixed-table-header">
					<td style="text-align:center;vertical-align:middle;">T1</td>
					<td style="text-align:center;vertical-align:middle;">T2</td>
					<td style="text-align:center;vertical-align:middle;">T3</td>
				</tr>
				<if condition="$result eq NULL">
				<tr>
					<td colspan="12" class="text-center">暂无相关内容</td>
				</tr>
				<else />
				<foreach name="result" item="vo">
					<foreach name="vo['detail']" item="wo" key="kk">
					<if condition="$key%2 eq 1"><tr class="interlaced-color"><else/><tr></if>
						<if condition="$kk eq 0">
							<td rowspan="{$vo['sum']}">{$vo['cname']}</td>
						</if>
						<td>{$wo['name']}</td>
						<td>{$wo['unit']}</td>
						<td class="all_w"><span>{$wo['weight']}</span><if condition="$vo['cid'] neq 5">%<else />分</if></td>
						<td>{$wo['cycle']}</td>
						<if condition="$status eq -1 && is_permission('PB',NULL,1)">
						<td>
							<a href="javascript:;" class="edit mr5" mid="{$wo['id']}" s_cid="{$vo['cid']}" s_name="{$wo['name']}" s_unit="{$wo['unit']}" s_weight="{$wo['weight']}" s_cycle="{$wo['cycle']}"  data-toggle="tooltip" data-placement="left" title="编辑"><i class="glyphicon glyphicon-edit"></i></a>
							<a href="javascript:;" mid="{$wo['id']}" action="delete" data-toggle="tooltip" data-placement="left" title="删除" class="btn-delete"><i class="glyphicon glyphicon-trash"></i></a>
						</td>
						<td><input type="hidden" name="m_id[]" value="{$wo['id']}" class="form-control required-text w100" autocomplete="off"><input type="text" name="t1[]" value="{$wo['t1']}" class="form-control required-text w100" autocomplete="off"></td>
						<td><input type="text" name="t2[]" value="{$wo['t2']}" class="form-control required-text w100" autocomplete="off"></td>
						<td><input type="text" name="t3[]" value="{$wo['t3']}" class="form-control required-text w100" autocomplete="off"></td>
						<td><input type="text" name="c_value[]" value="{$wo['c_value']}" class="form-control required-text w100" autocomplete="off"></td>
						<td><input type="text" name="score[]" value="{$wo['score']}" class="form-control required-text w100" autocomplete="off"></td>
						<else />
						<td></td>
						<td>{$wo['t1']}</td>
						<td>{$wo['t2']}</td>
						<td>{$wo['t3']}</td>
						<td>{$wo['c_value']}</td>
						<td>{$wo['score']}</td>
						</if>
					</tr>
					</foreach>
				</foreach>
				<tr class="interlaced-color">
					<td><b>合计</b></td>
					<td style="border:none" colspan="2"></td>
					<td class="all_p" style="border:none"><span>{$sum_w}</span>%</td>
					<td style="border:none" colspan="2"></td>
					<td>{$sum_t1}</td>
					<td>{$sum_t2}</td>
					<td>{$sum_t3}</td>
					<td>{$sum_c_value}</td>
					<td>{$sum_score}</td>
				</tr>
				</if>
			</table>
		</div>
		<if condition="is_permission('PB',NULL,1)">
			<if condition="$result neq NULL">
			<div class="form-btn-item">
				<p class="red Text_c mb10"></p>
				<if condition="$status eq -1">
					<button class="btn btn-submit" type="button">提交</button>
				<else />
					<button class="btn lost_submit" type="button">放弃提交</button>
				</if>
			</div>
			</form>
			</if>
		</if>
		</if>
	</div>
</div>
<!--弹框-->
<div class="modal fade" id="edit-modal">
	<div class="modal-dialog w700">
		<div class="modal-content">
			<div class="modal-header">
				<h4></h4>
				<i class="fa fa-times" aria-hidden="true" data-dismiss="modal"></i>
			</div>
			<div class="modal-body" style="line-height:30px;">
				<table class="table table-bordered">
					<tr>
						<td width="150" class="text-right"><strong><span class="asterisk">*</span>指标类型</strong></td>
						<td>
							<select name="cid" class="form-control classify classify_select" autocomplete="off">
								<option value="-10" selected>请选择</option>
								<foreach name="cids_list" item="vo">
									<option value="{$vo['name1']}">{$vo['name2']}</option>
								</foreach>
							</select>
							<input type="text" name="zb_input" class="form-control select-add-text ml5" style="width:195px" autocomplete="off">
							<span class="error-item">必填项</span>
							<span class="error-item">该指标类型已存在</span>
						</td>
					</tr>
					<tr>
						<td class="text-right"><strong><span class="asterisk">*</span>关键绩效指标（KPI）</strong></td>
						<td>
							<select name="name" class="form-control classify classify_select" autocomplete="off">
								<option value="-10" selected>请先选择指标类型</option>
							</select>
							<input type="text" name="kpi_input" class="form-control select-add-text ml5" style="width:195px" autocomplete="off">
							<span class="error-item">必填项</span>
							<span class="error-item">该指标类型已存在</span>
						</td>
					</tr>
					<tr>
						<td class="text-right" width="74"><strong>单位</strong></td>
						<td>
							<input type="text" name="unit" class="form-control" autocomplete="off" />
							<span class="error-item">必填项</span>
						</td>
					</tr>
					<tr>
						<td class="text-right" width="74"><strong><span class="asterisk">*</span>权重</strong></td>
						<td>
							<input type="text" name="weight" class="form-control w50 mr10" autocomplete="off" maxlength="3" onKeyUp="value=value.replace(/[^\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" /><em class="qz_text hide">±5</em><i class="qz_f">%</i>
							<span class="error-item">必填项</span>
							<span class="error-item">权重总和不能大于100%</span>
							 <span class="error-item">必须为整数</span> 
						</td>
					</tr>
					<tr>
						<td class="text-right" width="74"><strong><span class="asterisk">*</span>考核周期</strong></td>
						<td>
							<input type="text" name="cycle" class="form-control name" autocomplete="off" />
							<span class="error-item">必填项</span>
						</td>
					</tr>
				</table>
			</div>
			<div class="modal-footer">
				<span class="red mr10"></span><button type="button" class="btn btn-affirm">确认</button><button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
			</div>
		</div>
	</div>
</div>
<include file="Include:javascript"/>
<script type="text/javascript">
$(function(){
	$(".classify_select").on('change',function(){
		if($(this).val()==-10){
			$(this).nextAll('input').show();
		}else{
			$(this).nextAll('input').val('').hide();
		}
	});
	//删除
	$(".btn-delete").ajaxModal({"title_text":"确认提示框","body_text":"您确定要删除吗？","url":"__APP__/Hr/jixiao_pbc_ajax","data":{"id":"mid","action":"action"}});

	$(document).on("change","[name='u_id']",function(){
		var val = $(this).val();
		window.location.href="__APP__/Hr/jixiao_pbc_user/u_id/"+val;
	});
	//编辑
	$('.edit').click(function(){
		var modal = $("#edit-modal");
		modal.find(".modal-header h4").text("编辑人员PBC");
		modal.modal();
		$('.select-add-text').val('');
		var mid = $(this).attr("mid"),
			cid = $(this).attr('s_cid'),
			names = $(this).attr('s_name'),
			unit = $(this).attr('s_unit'),
			weight = $(this).attr('s_weight'),
			cycle = $(this).attr('s_cycle'),
			num = parseInt($('.all_p span').text()) - parseInt($(this).parents('tr').find('.all_w').find('span').text());
		
		modal.find(".btn-affirm").attr({"mid":mid});
		modal.find('.select2').remove();
		modal.find("[name='cid']").val(cid).select2().siblings('input').hide();
		u_id="{$u_id}";
		$.ajax({
			type:"POST",
			async:false,
			dataType:"json",
			data:{"cid":cid,"u_id":u_id,"action":"data"},
			url:"__APP__/Hr/jixiao_pbc_ajax",
			success:function(data){
				if(data){
					var option = "<option value='-10' selected>请选择</option>";
					for(var i=0;i<data.length;i++){
						option+= "<option value="+data[i].name+"";
						if(names == data[i].name){
							option+= " selected";
						}
						option+= ">"+data[i].name+"</option>";
					}
					$("[name='name']").html(option).trigger('change').select2();
				}else{
					$("[name='name']").html("<option value='-10' selected>请选择</option>").trigger('change').select2();
					$("[name='kpi_input']").val(names);
				}
			}
		});
		modal.find("[name='unit']").val(unit);
		modal.find("[name='cycle']").val(cycle);
		modal.find('.btn-affirm').attr('date_type','edit');
		modal.find('.btn-affirm').attr('date_n',num);
		if(cid!=5 && cid!=6){
			modal.find("[name='weight']").show().val(weight);
			modal.find(".qz_f").html("%");
			modal.find(".qz_text").hide();
		}else if(cid==5){
			modal.find("[name='weight']").hide().val(weight);
			modal.find(".qz_f").html("分");
			modal.find(".qz_text").show().html(weight);
		}else if(cid==6){
			modal.find("[name='weight']").hide().val(weight);
			modal.find(".qz_f").html("%");
			modal.find(".qz_text").show().html(weight);
		}
	})

	//添加
	$(".btn-add").on("click",function(){
		var modal = $("#edit-modal");
		modal.find(".modal-header h4").text("添加人员PBC");
		modal.modal();
		$('.select-add-text').val('');
		modal.find('.btn-affirm').attr('date_type','add');
		modal.find('.btn-affirm').attr('date_n',$('.all_p span').text());
	});

	//确定
	$("#edit-modal").find(".btn-affirm").on("click",function(){
		var tag = true,
			mid = $(this).attr("mid"),
			action = $(this).attr('date_type'),
			num = 100 - parseInt($(this).attr('date_n')),
			modal = $("#edit-modal"),
			cid = $("[name='cid']").val();

		modal.find(".classify_select").each(function(){
			var $this = $(this),
				val = $this.val(),
				text = $this.nextAll(".select-add-text").val();
			if(val==-10 && text==""){
				$this.siblings(".error-item").eq(0).show();
				tag = false;
			}else{
				$this.find("option").each(function(){
					if($(this).text()==text){
						$this.siblings(".error-item").eq(1).show()
						tag = false;
						return false;
					}
				});
			}
		});

		if(cid!=5 && cid!=6){
			modal.find("[name='weight']").each(function(){
				var val = $(this).val();
				if(val!='' && !/^(0|\+?[1-9][0-9]*)$/.test(val)){
					tag = false;
					$(this).siblings(".error-item").eq(2).show();
				}
				if(val>100){
					tag = false;
					$(this).siblings(".error-item").eq(1).show();
				}
				if(val>num){
					tag = false;
					$(this).siblings(".error-item").eq(1).show();
				}
			})
			modal.find(".name").each(function(){
				var val = $(this).val();
				if(val=="" || /^\s+$/.test(val)){
					$(this).siblings(".error-item").eq(0).show();
					tag = false;
				}
			});
			modal.find("[name='weight']").each(function(){
				var val = $(this).val();
				if(val=="" || /^\s+$/.test(val)){
					$(this).siblings(".error-item").eq(0).show();
					tag = false;
				}
			});
		}else{
			modal.find(".name").each(function(){
				var val = $(this).val();
				if(val=="" || /^\s+$/.test(val)){
					$(this).siblings(".error-item").eq(0).show();
					tag = false;
				}
			});
		}
		
		if(tag){
			var cid = modal.find("[name='cid']").val(),
				name = modal.find("[name='name']").val(),
				unit = modal.find("[name='unit']").val(),
				weight = modal.find("[name='weight']").val(),
				cycle = modal.find("[name='cycle']").val(),
				zb_input = modal.find("[name='zb_input']").val(),
				kpi_input = modal.find("[name='kpi_input']").val(),
				u_id="{$u_id}";

			$.ajax({
				type:"POST",
				async:false,
				dataType:"json",
				data:{"action":action,"id":mid,"u_id":u_id,"name":name,"cid":cid,"unit":unit,"weight":weight,"cycle":cycle,"zb_input":zb_input,"kpi_input":kpi_input},
				url:"__APP__/Hr/jixiao_pbc_ajax",
				success:function(data){
					if(data.status){
						success_pop(data.status);
						modal.hide();
					}else{
						modal.find('.modal-footer span').html(data.msg);
					}
				}
			});
		}
	});
	
	//指标类型联动关键绩效指标（KPI）
	$("[name='cid']").on("change",function(){
		var val = $(this).val();
		$('#edit-modal').find('.error-item').hide();
		$('.modal-footer .red').html('');
		if(val==-10){
			$("[name='name']").html("<option value='-10' selected>请先选择指标类型</option>").trigger('change')
			$("[name='weight']").show();
			$('.qz_text').hide();
			$('.qz_f').html("%");
		}else{
			if(val==5){
				$("[name='weight']").hide().val('±5');
				$('.qz_text').html('±5').show();
				$('.qz_f').html("分");
			}else if(val==6){
				$("[name='weight']").hide().val('0');
				$('.qz_text').html('0').show();
				$('.qz_f').html("%");
			}else{
				$("[name='weight']").show();
				$('.qz_text').hide();
				$('.qz_f').html("%");
			}
			$.ajax({
				type:"POST",
				async:false,
				dataType:"json",
				data:{"cid":val,"action":"data"},
				url:"__APP__/Hr/jixiao_pbc_ajax",
				success:function(data){
					if(data){
						var option = "<option value='-10' selected>请选择</option>";
						for(var i=0;i<data.length;i++){
							option+="<option value="+data[i].name+">"+data[i].name+"</option>";
						}
						$("[name='name']").html(option).trigger('change')
					}else{
						$("[name='name']").html("<option value='-10' selected>请先选择指标类型</option>").trigger('change')
					}
				}
			});
		}
	});

	//关键绩效指标（KPI）联动详情
	$("[name='name']").on("change",function(){
		var name = $(this).val(),
			cid = $("[name='cid']").val();
		$.ajax({
			type:"POST",
			async:false,
			dataType:"json",
			data:{"name":name,"cid":cid,"action":"info"},
			url:"__APP__/Hr/jixiao_pbc_ajax",
			success:function(data){
				if(data){
					$("[name='unit']").val(data.unit);
					$("[name='weight']").val(data.weight);
					$("[name='cycle']").val(data.cycle);
				}
			}
		})
		if(name==-10){
			if(cid!=5 && cid!=6){
				$("[name='unit'],[name='weight'],[name='cycle']").val('');
			}
		}
	});

	//同步
	$(".synchro").ajaxModal({"title_text":"确认提示框","body_text":"您确定要同步到指标库吗？","url":"__APP__/Hr/jixiao_pbc_ajax","data":{"u_id":"u_id","action":"action"}});

	//提交
	$('.btn-submit').click(function(){
		var tag = true;
		if($("[name='out_uid']").val()==-10){
			tag = false;
			$('.form-btn-item .red').html("请选择发约人和日期");
		}
		$('.Wdate').each(function(){
			if($(this).val()==''){
				tag = false;
				$('.form-btn-item .red').html("请选择发约人和日期");
			}
		})
		if(tag){
			var u_id="{$u_id}";
			$.ajax({
				type:"POST",
				async:false,
				dataType:"json",
				data:$('.number_validate').serialize()+"&action=do_user&u_id="+u_id,
				url:"__APP__/Hr/jixiao_pbc_ajax",
				success:function(data){
					success_pop(data.status);
				}
			})
		}
	})
	//放弃提交
	$('.lost_submit').click(function(){
		var u_id="{$u_id}";
		$.ajax({
			type:"POST",
			async:false,
			dataType:"json",
			data:{"action":"give_user","u_id":u_id},
			url:"__APP__/Hr/jixiao_pbc_ajax",
			success:function(data){
				success_pop(data.status);
			}
		})
	})
	
	//隐藏错误提示
	$('.select-add-text').on("focus",function(){
		$(this).nextAll(".error-item").hide();
	});
	$("#edit-modal").find(".classify").on("change",function(){
		$(this).nextAll(".error-item").hide();
	});
	$("#edit-modal").find(".name,.date,[name='weight']").on("focus",function(){
		$(this).nextAll(".error-item").hide();
	});

	//取消
	$("#edit-modal").on('hidden.bs.modal',function(){
		$(this).find(".error-item").hide();
		$(this).find(".name,.date").val("");
		$(this).find("select").val(-10).select2();
		$(this).find(".btn-affirm").removeAttr("mid");
		$(this).find('.select-add-text').show();
		$(this).find("[name='name']").html('<option value="-10">请选择</option>');
		$(this).find('.modal-footer').find('.red').html('');
		$(this).find("[name='weight']").val('').show();
		$(this).find(".qz_text").hide();
		$(this).find(".qz_f").html('%');
	});
});
</script>
</body>
</html>